package com.crayon.account.fragments.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.crayon.util.UTILPieChartDemo01View;

import org.afree.chart.AFreeChart;
import org.afree.data.general.PieDataset;

public class FragmentPieChart extends Fragment{
	
	public interface OnPieChartDataBinder{
		public PieDataset OnPieDataSet();
		public AFreeChart createChart(PieDataset dataset);
	}
	
	
	
	OnPieChartDataBinder onPieChartDataBinder;
	AFreeChart mChart;
	
	public static FragmentPieChart onCreate(AFreeChart chart){
		FragmentPieChart f = new FragmentPieChart();
		Bundle bundle =new Bundle();
		bundle.putSerializable("chart", chart);
		f.setArguments(bundle);
		return f;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		if(getArguments()!=null)
		mChart = (AFreeChart)getArguments().getSerializable("chart");
		super.onCreate(savedInstanceState);
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
//		return inflater.inflate(R.layout.fragment_child_piechart,container, false);
		if(mChart!=null){
			return new UTILPieChartDemo01View(getActivity(), mChart);
		}
		return new UTILPieChartDemo01View(getActivity(),getOnPieChartDataBinder());
	}

	public OnPieChartDataBinder getOnPieChartDataBinder() {
		return onPieChartDataBinder;
	}

	public void setOnPieChartDataBinder(OnPieChartDataBinder onPieChartDataBinder) {
		this.onPieChartDataBinder = onPieChartDataBinder;
	}
}
